package com.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import android.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
/**
 * 公用帮助类
 *
 */
@SuppressLint({ "SimpleDateFormat", "UseValueOf", })
public class EncodingUtil {
	/**
	 * 返回时间格式 20140113000000
	 * @param date
	 * @return
	 */
	public static String getThisDayDate(Calendar date) {
		String year = date.get(Calendar.YEAR) + "";
		// 月份转(不够用0补)
		String month = addZero((date.get(Calendar.MONTH) + 1) + "");
		// 日转8进制(不够用0补)
		String day = addZero(date.get(Calendar.DATE) + "");
		return year + month + day+"000000";
	}
	/**
	 * 返回时间格式 20140113121212
	 *
	 * @param date
	 * @return
	 */
	public static String getThisDBDayDate(Calendar date) {
		String year = date.get(Calendar.YEAR) + "";
		// 月份转(不够用0补)
		String month = addZero((date.get(Calendar.MONTH) + 1) + "");
		// 日转8进制(不够用0补)
		String day = addZero(date.get(Calendar.DATE) + "");
		String hh = addZero(date.get(Calendar.HOUR_OF_DAY) + "");
		String mm = addZero(date.get(Calendar.MINUTE) + "");
		String ss = addZero(date.get(Calendar.SECOND) + "");
		return year + month + day + hh + mm + ss;
	}

	/**
	 * 前补0
	 * @return
	 */
	public static String addzero(String str, int num) {
		for (int i = 0; i < num * 2; i++) {
			if (str.length() < num * 2)
				str = "0" + str;
			else
				break;
		}
		return str;
	}

	/**
	 * 获取SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");// 设置日期格式
	 * @param date
	 * @return
	 */
	public static String getSessionKeyDate(Date date){
		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");// 设置日期格式
			return df.format(date);
		} catch (Exception e) {
			return null;
		}
	}
	/**
	 * 获取SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");// 设置日期格式
	 * @param date
	 * @return
	 */
	public static Date getSessionKeyDate(String date){
		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");// 设置日期格式
			return df.parse(date);
		} catch (Exception e) {
			return null;
		}
	}

	private static long lastClickTime;
	/**
	 * 解析挑战幀中的时间戳 格式"yyyy/MM/dd HH:mm:ss"
	 * @param str
	 * @return
	 */
	public static String analysisDate(String str){
		try {
			//DE 07 01 06 01 09 1B 14
			String date = hexToDec(str.substring(2, 4)+str.substring(0, 2));
			date=date +"/"+hexToDec(str.substring(4, 6));
			date=date +"/"+hexToDec(str.substring(6, 8));
			date=date +" "+hexToDec(str.substring(10, 12));
			date=date +":"+hexToDec(str.substring(12, 14));
			date=date +":"+hexToDec(str.substring(14, 16));
			return date;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 将String转化Date 格式"yyyy/MM/dd HH:mm:ss"
	 * @param str
	 * @return
	 */
	public static Date dateFormat(String str){
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			Date date= sdf.parse(str);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 将String转化Date 格式"yyyyMMddHHmmss"
	 * @param str
	 * @return
	 */
	public static Date DateFormat(String str){
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			Date date= sdf.parse(str);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static byte[] subByte(int fistPosion, int b, byte[] bytes) {
		byte[] byt = new byte[b * 2];

		for (int i = 0; i < byt.length; i++) {
			byt[i] = bytes[fistPosion];
			fistPosion++;
		}

		return byt;
	}

	/**
	 * 前补零
	 *
	 * @param date
	 * @param leng
	 * @return
	 */
	public static String topAddZero(String date, int leng) {
		while (date.length() < leng) {
			date = "0" + date;
		}
		return date;
	}

	/**
	 * 判断时间
	 *
	 * @return
	 */
	public static boolean isFastDoubleClick(long times) {
		long time = System.currentTimeMillis(); // 1、当前时间
		long timeD = time - lastClickTime; // 2、获得时间差
		if (0 < timeD && timeD < times) { // 3、
			return true;
		}
		lastClickTime = time;
		return false;
	}

	/**
	 * 截串方法
	 *
	 * @param onSet
	 * @param octet
	 * @param context
	 * @return
	 */
	public static String subString(int onSet, int octet, String context) {
		if (context != null && "".equals(context)) {
			return context.substring(onSet * 2, octet * 2);
		} else {
			return context;
		}
	}

	/**
	 * 发送报文
	 *
	 * @param context
	 * @return
	 */
	public static byte[] sendBaowen(String context) {
		return EncodingUtil.hex2byte(EncodingUtil.change(context));
	}

	/**
	 * 获取每次的文件名字 yyMMddHHmmss
	 *
	 * @return
	 */
	public static String getPhoneName() {
		SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");// 设置日期格式
		return df.format(new Date());
	}

	/**
	 * 获取文件名 时间
	 *
	 * @return
	 */
	public static String getFileName() {
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");// 设置日期格式
		return df.format(new Date());// new Date()为获取当前系统时间
	}

	/**
	 * 补0
	 *
	 * @param info
	 * @param number
	 * @return
	 */
	public static String jointZero(String info, int number) {
		String result = "";
		int x = info.length();
		for (int i = x; i < number; i++) {
			result += "0";
		}
		return result + info;
	}

	/**
	 * 拼接上传幀
	 *
	 * @param strs
	 * @return
	 */
	public static String joint(String... strs) {
		String result = "";
		for (int i = 0; i < strs.length; i++) {
			if (i == strs.length - 1) {
				break;
			}
			result += (strs[i] + ",");
		}
		return result;
	}

	/**
	 * Long类型转换16进制
	 *
	 * @param date
	 * @param number
	 * @return
	 */
	public static String LongTosix(long date, int number) {
		String six = Long.toHexString(date);
		String zero = "";
		for (int i = 0; i < number; i++) {
			if (six.length() < number) {
				zero += "0";
			}
		}
		return zero + six;
	}

	/**
	 * 车辆颜色
	 *
	 * @param color
	 * @return
	 */
	public static String vehicleColor(String color) {
		String colo = "";
		try {
			colo = Integer.parseInt(color) + "";
		} catch (Exception e) {

		}
		if ("0".equals(color)) {
			colo = "蓝";
		} else if ("1".equals(color)) {
			colo = "黄";
		} else if ("2".equals(color)) {
			colo = "黑";
		} else if ("3".equals(color)) {
			colo = "白";
		} else if ("4".equals(color)) {
			colo = "绿";
		} else {
			colo = "未定义";
		}
		return colo;
	}

	/**
	 * 判断车辆类型
	 *
	 * @param type
	 * @return
	 */
	public static String vehicleType(String type) {
		String str = "";
		if ("01".equals(type)) {
			str = "A型车";
		} else if ("02".equals(type)) {
			str = "B型车";
		} else if ("03".equals(type)) {
			str = "C型车";
		} else if ("04".equals(type)) {
			str = "D型车";
		} else if ("05".equals(type)) {
			str = "E型车";
		} else if ("06".equals(type)) {
			str = "F型车";
		} else if ("11".equals(type)) {
			str = "货车A型车";
		} else if ("12".equals(type)) {
			str = "货车B型车";
		} else if ("13".equals(type)) {
			str = "货车C型车";
		} else if ("14".equals(type)) {
			str = "货车D型车";
		} else if ("15".equals(type)) {
			str = "货车E型车";
		} else if ("16".equals(type)) {
			str = "货车F型车";
		} else if ("".equals(type)) {
			str = "未定义";
		} else {
			str = "非法车型";
		}
		return str;
	}

	/**
	 * 字符串转ASC码
	 *
	 * @param c
	 * @return
	 */
	public static String getAscii(String c) {
		String s = String.valueOf(c);
		byte[] bytes = s.getBytes();
		String dd = "";
		for (int i = 0; i < bytes.length; i++)
			dd += Integer.toHexString(bytes[i] & 0xff);
		return dd;

	}

	/**
	 * 2个MAP相加
	 *
	 * @param map1
	 * @param map2
	 * @return
	 */
	public static Map<String, String> addMap(Map<String, String> map1,
											 Map<String, String> map2) {
		Iterator<Entry<String, String>> it = map2.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String, String> entry = (Entry<String, String>) it.next();
			map1.put(entry.getKey(), entry.getValue()); // 返回与此项对应的键
		}
		return map1;
	}

	/**
	 * 检查报文
	 *
	 * @param context
	 * @return
	 */
	public static String checkingBaowen(String context) {
		int leng = Integer.parseInt(EncodingUtil.hexToDec(
				context.substring(2, 4), 2)) * 2;
		return context.substring(0, leng);
	}

	/**
	 * 验证报文是否完整(如果完整截取返回,不完整返回null)
	 *
	 * @param context
	 * @return
	 */
	public static String checking(String context) {
		try {
			// 判断长度是否正确
			int index = context.indexOf("55AA");
			context = context.substring(index);
			int Length = EncodingUtil.hexStringToInt(context.substring(6, 10)) * 2 + 14;
			context = context.substring(0, Length);
			String bcc = context.substring(context.length() - 2);
			// 截取到发送的数据(总长度-2个字节计算到数据的最后位置)并转换下FE和FF
			String str = context.substring(4, context.length() - 2);
			// 得到比对校验
			String bc = EncodingUtil.yihuo(EncodingUtil.change(str)).toUpperCase();
			// 判断校验是否一致
			if (!bc.equals(bcc)) {
				throw new NoSuchElementException("异或失败!");
			}
			return context;
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 计算指纹码
	 *
	 * @param context
	 * @return
	 */
	public static String fingerCode(byte[] context) {
		return sha1(context).substring(0, 32);
	}

	/**
	 *
	 * 修改的
	 *
	 * @param context
	 * @return
	 */
	public static String subStr(String context, String strs, int type) {
		String sb = "";
		String first = "";
		String str = "";
		switch (type) {
			case 1:
				sb = strs.substring(0, 2);// 第十七字节
				first = context.substring(2);// 第一字节舍弃掉
				return sb + first;
			case 2:
				sb = strs.substring(2, 4);// 第十八字节
				first = context.substring(0, 2);// 第一字节
				str = context.substring(4);// 第二字节
				return first + sb + str;
			case 3:
				sb = strs.substring(4, 6);// 第十九字节
				first = context.substring(0, 4);// 第1-2字节
				str = context.substring(6, 32);// 第三字节
				return first + sb + str;
			case 4:
				sb = strs.substring(6, 8);// 第二十字节
				first = context.substring(0, 6);// 第1-3字节
				str = context.substring(8, 32);// 第三字节
				return first + sb + str;
		}
		return null;
	}

	/**
	 * sha1加密运算
	 *
	 * @param str
	 * @return
	 */
	public static String sha1(byte[] str) {
		try {
			MessageDigest sha1 = MessageDigest.getInstance("sha1");
			sha1.update(str);
			byte[] hash = sha1.digest();
			return byteArrayToHex(hash);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 把sha1运算后的结果转换字符串
	 *
	 * @param byteArray
	 * @return
	 */
	public static String byteArrayToHex(byte[] byteArray) {
		// 首先初始化一个字符数组，用来存放每个16进制字符
		char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'A', 'B', 'C', 'D', 'E', 'F' };
		// new一个字符数组，这个就是用来组成结果字符串的（解释一下：一个byte是八位二进制，也就是2位十六进制字符（2的8次方等于16的2次方））
		char[] resultCharArray = new char[byteArray.length * 2];
		// 遍历字节数组，通过位运算（位运算效率高），转换成字符放到字符数组中去
		int index = 0;
		for (byte b : byteArray) {
			resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
			resultCharArray[index++] = hexDigits[b & 0xf];
		}
		// 字符数组组合成字符串返回
		return new String(resultCharArray);
	}

	/**
	 * 十六进制转换十进制
	 *
	 * @param str
	 * @return
	 */
	public static String hexToDec(String str) {
		return Long.toString(Long.parseLong(str, 16));
	}

	/**
	 * 十六进制转换十进制
	 *
	 * @param str
	 * @return
	 */
	public static String hexToDec(String str, int number) {
		String strs = Long.toString(Long.parseLong(str, 16));
		for (int i = 0; i < number; i++) {
			if (strs.length() < number) {
				strs = "0" + strs;
			}
		}
		return strs;
	}

	/**
	 * ascii转字符串
	 *
	 * @return
	 */
	public static String asciiToString(String value) {
		try {//
			return new String(EncodingUtil.hex2byte(change(value)), "GBK");
		} catch (UnsupportedEncodingException e) {
			return value;
		}
	}

	/**
	 * 处理乱码中文
	 *
	 * @param context
	 * @return
	 */
	public static String convertEncoding(String temp) {
		try {
			// return new String(temp.getBytes("iso-8859-1"),"UTF-8");
			byte s[] = temp.getBytes("iso-8859-1");
			return new String(s, "GBK");
			// return temp;

		} catch (Exception e) {
			return "";
		}
	}

	/**
	 * 将byte转换为一个长度为8的bit（每bit代表一个标识值）
	 *
	 * @param b
	 *
	 * @return String
	 */
	public static String getBooleanArray(byte b) {
		boolean[] array = new boolean[8];
		for (int i = 7; i >= 0; i--) { // 对于byte的每bit进行判定
			array[i] = (b & 1) == 1; // 判定byte的最后一位是否为1，若为1，则是true；否则是false
			b = (byte) (b >> 1); // 将byte右移一位

		}
		String str = "";
		for (int i = 0; i < array.length; i++) {
			if (array[i]) {
				str += 1;
			} else {
				str += 0;
			}
		}
		return str;
	}

	/**
	 * 自由截字符串
	 *
	 * @param context
	 * @param firstIndex
	 * @param lastIndex
	 * @return
	 */
	public static String subString(String context, int firstIndex, int lastIndex) {
		return context.substring(firstIndex, lastIndex);
	}

	/**
	 * 终端序列号-1 交易失败
	 */
	/*public static void SetrandomNumber() {
		if (Integer.parseInt(CodeActivity.TradingNumber) > 0)
			CodeActivity.TradingNumber = (Integer
					.parseInt(CodeActivity.TradingNumber) - 1) + "";
	}*/

	/**
	 * 生成终端序列号+1
	 *
	 * @return
	 */
	public static String randomNumber(String str) {

		String number = (Integer.parseInt(str) + 1) + "";
		for (int i = 0; i < 8; i++) {
			if (number.length() < 8) {
				number = "0" + number;
			}
		}
		return number;
	}

	/**
	 * 后补0
	 *
	 * @param str
	 * @param number
	 * @return
	 */
	public static String addZeor(String str, int number) {
		String result = "";
		for (int i = 0; i < number - str.length(); i++) {
			if (str.length() < number) {
				result = result + "0";
			}
		}
		return str + result;
	}

	/**
	 * 补终端交易序号中的Zero
	 *
	 * @param str
	 * @param number
	 * @return
	 */
	public static String addZero(String str, int number) {
		String result = str;
		for (int i = 0; i < number - str.length(); i++) {
			if (str.length() < number) {
				result = "0" + result;
			}
		}
		return result;
	}

	/**
	 * Long类型转换Byte数组
	 *
	 * @param number
	 * @return
	 */
	public static byte[] longToByte(long number) {
		long temp = number;
		byte[] b = new byte[8];
		for (int i = 0; i < b.length; i++) {
			b[i] = new Long(temp & 0xff).byteValue();// 将最低位保存在最低位
			temp = temp >> 8;// 向右移8位
		}
		return b;
	}

	/**
	 * 将byte数组转换为 十六进制 string
	 *
	 * @param bArray
	 * @return
	 */
	public static String bytesToHexString(byte[] bArray) {
		StringBuffer sb = new StringBuffer(bArray.length);
		String sTemp;
		for (int i = 0; i < bArray.length; i++) {
			sTemp = Integer.toHexString(0xFF & bArray[i]);
			if (sTemp.length() < 2) {
				sb.append(0);
			}
			sb.append(sTemp.toUpperCase());
		}

		return sb.toString();
	}

	public static String sortStr(String cc) {
		StringBuffer stringbuffer = new StringBuffer();
		String sub;
		for (int i = cc.length(); i >= 2; i--) {
			sub = cc.substring(i - 2, i);
			if (!sub.equals("00")) {
				stringbuffer.append(sub);
			}
			i--;
		}
		return stringbuffer.toString();
	}

	/**
	 * 异或运算 字符串每16进制字节以空格分开
	 *
	 * @return
	 */
	public static String yihuo(String str) {

		String[] arges = str.split(" ");
		int shijinzhi = Integer.parseInt(arges[0], 16);
		for (int i = 1; i < arges.length; i++) {
			shijinzhi = shijinzhi ^ Integer.parseInt(arges[i], 16);
		}
		String result = Integer.toHexString(shijinzhi);
		if (result.length() < 2) {
			return "0" + result;
		}
		return result.toUpperCase();
	}

	/**
	 * 十进制转换十六进制(位数不够补0)
	 *
	 * @param num
	 *            十进制参数
	 * @param number
	 *            位数（并非字节数）
	 * @return
	 */
	public static String desToHex(int num, int number) {
		int Num = num;// 要转换的数字

		int length = 32;

		char[] result = new char[length];

		do {

			result[--length] = digits[Num & 15];

			Num >>>= 4;

		} while (Num != 0);
		String str = "";
		for (int i = length; i < result.length; i++) {

			str += result[i];
		}
		if (str.length() < number) {
			String count = "";
			for (int i = str.length(); i < number; i++) {
				count += "0";
			}
			str = new String(count + str);
		}
		return str;
	}

	/**
	 * 10进制转16进制
	 *
	 * @param num
	 * @return
	 */
	public static String desToHex(int num) {
		int Num = num;// 要转换的数字

		int length = 32;

		char[] result = new char[length];

		do {

			result[--length] = digits[Num & 15];

			Num >>>= 4;

		} while (Num != 0);
		String str = "";
		for (int i = length; i < result.length; i++) {

			str += result[i];
		}
		return str;
	}

	/****************
	 * 16进制字符串转为十进制整数 如 将0E转为十进制的14
	 */
	public static int hexStringToInt(String value) {
		return Integer.valueOf(value, 16);
	}

	// 16进制工具
	static final char digits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',

			'9', 'A', 'B', 'C', 'D', 'E', 'F' };

	/**
	 * 改变格式 4e2dfc 4e 2d fc
	 *
	 * @param content
	 * @return
	 */
	public static String change(String content) {
		String str = "";
		for (int i = 0; i < content.length(); i++) {
			if (i % 2 == 0) {
				str += " " + content.substring(i, i + 1);
			} else {
				str += content.substring(i, i + 1);
			}
		}
		return str.trim();
	}

	/**
	 * 把 文本格式的 16进制码 转为 Byte[]
	 *
	 * @param value
	 * @return
	 */
	public static byte[] hex2byte(String value) {
		String[] str = value.split(" ");
		byte[] b = new byte[str.length];
		for (int i = 0; i < str.length; i++) {

			b[i] = (byte) hexStringToInt(str[i]);

		}
		return b;
	}

	/**
	 * AB指令中当前时间
	 *
	 * @param date
	 * @return
	 */
	public static String getTime(Calendar date) {
		return date.get(Calendar.YEAR)
				+ EncodingUtil.addZero(date.get(Calendar.MONTH) + 1 + "")
				+ EncodingUtil.addZero(date.get(Calendar.DATE) + "");
	}

	/**
	 * 返回当前时间的要求串
	 *
	 * @param date
	 * @return
	 */
	public static String getDate(Calendar date) {
		// 年份转16进制(低字节在前,高字节在后)
		String year = desToHex(date.get(Calendar.YEAR));
		year = year.substring(1, 3) + "0" + year.substring(0, 1);
		// 月份转(不够用0补)
		String month = EncodingUtil.desToHex(date.get(Calendar.MONTH) + 1, 2);
		// 日转8进制(不够用0补)
		String day = plus(EncodingUtil.desToHex(date.get(Calendar.DATE)));
		// 星期(星期是1-7,所以减1)
		String week = plus((date.get(Calendar.DAY_OF_WEEK) - 1) + "");
		// 小时(0-23)
		String hour = EncodingUtil.desToHex(date.get(Calendar.HOUR_OF_DAY), 2);
		// 分
		String minute = EncodingUtil.desToHex(date.get(Calendar.MINUTE), 2);
		// 秒
		String second = EncodingUtil.desToHex(date.get(Calendar.SECOND), 2);
		return year + month + day + week + hour + minute + second;
	}

	public static String dbDate(Calendar date) {
		String year = date.get(Calendar.YEAR) + "";
		// 月份转(不够用0补)
		String month = addZero((date.get(Calendar.MONTH) + 1) + "");
		// 日转8进制(不够用0补)
		String day = addZero(date.get(Calendar.DATE) + "");
		return year + month + day;
	}


	/**
	 * 解析时间字符串
	 *
	 * @param date
	 * @return
	 */
	public static String toDate(String date) {
		date = date.substring(2, 4) + date.substring(0, 2) + date.substring(4);
		String result = "";
		result += sixToTen(date.substring(0, 4));
		result += hexToDec(date.substring(4, 6), 2);
		result += hexToDec(date.substring(6, 8), 2);
		// result += date.substring(8, 10);
		result += hexToDec(date.substring(10, 12), 2);
		result += hexToDec(date.substring(12, 14), 2);
		result += hexToDec(date.substring(14, 16), 2);
		return result;
	}

	/**
	 * 时间前面加0(时分秒)
	 *
	 * @param value
	 * @return
	 */
	public static String addZero(String value) {
		if (value.length() < 2) {
			return new String("0" + value);
		}
		return value;
	}
	/**
	 * 前面加0
	 *
	 * @param value
	 * @return
	 */
	public static String inserZero(String value,int number) {
		String str = value;
		while(true){
			if(str.length()<number){
				str = "0"+str;
			}else{
				break;
			}
		}
		return str;
	}
	/**
	 * 八进制转十进制(日期不够两位前面补0)
	 *
	 * @param value
	 * @return
	 */
	public static String converEightToTen(String value) {
		String str = eightToTen(value);
		if (str.length() < 2) {
			return new String("0" + str);
		}
		return str;
	}

	/**
	 * 减去星期(时分秒)前面的0
	 *
	 * @param value
	 * @return
	 */
	public static String minusZero(String value) {
		if (value.substring(0, 1).equals("0")) {
			return value.substring(1, 2);
		}
		return value;
	}

	/**
	 * 十六进制转换十进制(会舍弃的前面的0)
	 *
	 * @param value
	 * @return
	 */
	public static String sixToTen(String value) {
		return Integer.valueOf(value, 16).toString();
	}

	/**
	 * 十六进制转换十进制(会舍弃的前面的0)
	 *
	 * @param value
	 * @return
	 */
	public static String sixToTen(String value, int count) {
		String str = Integer.valueOf(value, 16).toString();
		str = Integer.valueOf(value, 16).toString();
		String zero = "";
		for (int i = 0; i < count; i++) {
			if (str.length() > count) {
				zero += "0";
			}
		}
		return zero + str;
	}

	/**
	 * 八进制转换10进制
	 *
	 * @param value
	 * @return
	 */
	public static String eightToTen(String value) {
		return Integer.valueOf(value, 8).toString();
	}

	/**
	 * 字节不够1字节的前面加0
	 *
	 * @param value
	 * @return
	 */
	public static String plus(String value) {
		if (value.length() < 2) {
			return "0" + value;
		}
		return value;
	}

	/**
	 * 十进制转八进制
	 *
	 * @param value
	 * @return
	 */
	public static String desToEight(int value) {
		return Integer.toOctalString(value);
	}

	/**
	 * 传入字符串(字节不够前补O)
	 *
	 * @param str
	 * @param length
	 * @return
	 */
	public static String plusZero(String str, int length) {
		String context = "";
		for (int i = str.length(); i < length; i++) {
			context += "0";
		}
		return context + str;
	}

	/**
	 * 获取手机系统型号
	 * @return 0:M10_JL(old)
	 * 	1:module_slm751(new)
	 */
	public static int getSystemType() {
		int nRet = 0;
		String type = android.os.Build.MODEL;
		if (!TextUtils.isEmpty(type)) {
			if (!"M10_JL".equals(type)) {
				nRet = 1;
			}
		}
		return nRet;
	}

}
